package com.herui.iot.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.herui.sdyu_lib.base.BaseAppcation;


/**
 * Created by Administrator on 2016/5/27.
 */
public class NetUtils {

    public static boolean isNetActive() {
        ConnectivityManager connectivityManager = (ConnectivityManager) BaseAppcation
                .getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();

        boolean isConnect = false;
        if (netInfo != null && netInfo.isAvailable()) {
            //网络连接
            String name = netInfo.getTypeName();
            if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                //WiFi网络
                isConnect = true;
            } else if (netInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
                //有线网络
                isConnect = true;
            } else if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                //3g网络
                isConnect = true;
            }
        } else {
            //网络断开
            isConnect = false;
        }

        return isConnect;
    }
}
